package gbench.appdemo.myworld.junit;


import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;
import gbench.appdemo.myworld.data.MyDataApp;
import gbench.common.tree.LittleTree.IRecord;
import static gbench.common.tree.LittleTree.*;

/**
 * 
 * @author gbench
 *
 */
public class JunitData {
    
    @Test
    public void foo() {
        final var dataApp = new MyDataApp("db1");// 打开一个数据库 db1,db1 需要在创建
        final var builder = IRecord.builder("id,name,drcr,amount,createTime");
        final var rec = builder.get(1l,"zhangsan",0,2000d,LocalDateTime.now());// 生成一个数据示意图
        final var db = dataApp.getDataBase();
        final var namedsql = new SQL("entry",rec);
        final var sql = namedsql.createTable().get(2);
        System.out.println(sql);
        dataApp.withTransaction(sess->{
            if(db.exists("entry"))sess.sqlexecute("drop table entry");
            sess.sqlexecute(sql);
            final var insert = namedsql.insert();
            sess.sqlexecute(insert);
            sess.sql2records("select * from entry").forEach(e->{
                System.out.println(e);
            });
        });
    }

}
